<?php

/**
 * This is the model class for table "hs_room_surplus".
 *
 * The followings are the available columns in table 'hs_room_surplus':
 * @property integer $id
 * @property integer $room_id
 * @property string $sur_date
 * @property integer $surplus_count
 * @property string $market_price
 * @property string $discount_price
 *
 * The followings are the available model relations:
 * @property Room $room
 */
class RoomSurplus extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return RoomSurplus the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'hs_room_surplus';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('sur_date, surplus_count, market_price, discount_price', 'required'),
			array('room_id, surplus_count', 'numerical', 'integerOnly'=>true),
			array('market_price, discount_price', 'length', 'max'=>12),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, room_id, sur_date, surplus_count, market_price, discount_price', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'room' => array(self::BELONGS_TO, 'Room', 'room_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'room_id' => 'Room',
			'sur_date' => 'Sur Date',
			'surplus_count' => 'Surplus Count',
			'market_price' => 'Market Price',
			'discount_price' => 'Discount Price',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('room_id',$this->room_id);
		$criteria->compare('sur_date',$this->sur_date,true);
		$criteria->compare('surplus_count',$this->surplus_count);
		$criteria->compare('market_price',$this->market_price,true);
		$criteria->compare('discount_price',$this->discount_price,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}